Skip to content

PostgreSQL: COMMENT ON CONSTRAINT / OPERATOR / RULE#33

Merged
fmguerreiro merged 1 commit intomainfrom
pgmold-297/comment-constraint-operator-rule
Apr 27, 2026
Merged

PostgreSQL: COMMENT ON CONSTRAINT / OPERATOR / RULE#33
fmguerreiro merged 1 commit intomainfrom
pgmold-297/comment-constraint-operator-rule

Conversation

@fmguerreiro
Copy link
Copy Markdown
Owner

Summary

Adds parser + AST coverage for the three remaining COMMENT ON … shapes that the fork had been silently rejecting:

  • COMMENT ON CONSTRAINT name ON [DOMAIN] target IS '…'
  • COMMENT ON OPERATOR name (left, right) IS '…' — each side may be NONE for unary operators
  • COMMENT ON RULE name ON target IS '…'

Changes

  • CommentObject gains Constraint, Operator, Rule variants in keyword_str and from_keyword.
  • New CommentOperatorArgs { left: Option<DataType>, right: Option<DataType> } carries the operand signature for OPERATOR, with Display rendering NONE for unary slots.
  • Statement::Comment gains two fields: operator_args: Option<CommentOperatorArgs> and on_domain: bool (only meaningful for Constraint). Existing destructures will need to add the two fields.
  • parse_comment dispatches the new variants:
    • OPERATOR uses parse_operator_name() (so +, myschema.@@, etc. round-trip) and a mandatory (slot, slot) signature.
    • CONSTRAINT and RULE require an ON <relation> tail; CONSTRAINT additionally accepts ON DOMAIN <domain>.
  • Refactors parse_drop_operator_signature to share a new parse_operator_arg_type_or_none() helper with parse_comment.
  • Bumps fork to 0.63.0; adds changelog/0.63.0.md.

Breaking changes

Statement::Comment adds operator_args and on_domain fields. Consumers that destructure all fields explicitly must add them; those using .. rest patterns are unaffected. Documented in changelog/0.63.0.md.

Test plan

  • cargo test --package pgmold-sqlparser (CI)
  • New tests in tests/sqlparser_postgres.rs:
    • parse_comment_on_constraint_on_table (binary form + IS NULL + IF EXISTS)
    • parse_comment_on_constraint_on_domain (unqualified + schema-qualified domain)
    • parse_comment_on_constraint_requires_relation_tail (error case)
    • parse_comment_on_operator_binary (public.+(INTEGER, INTEGER))
    • parse_comment_on_operator_prefix_left_none (unary prefix, NONE left)
    • parse_comment_on_operator_postfix_right_none (unary postfix, NONE right)
    • parse_comment_on_operator_requires_argument_list (error case)
    • parse_comment_on_rule + IS NULL
    • parse_comment_on_rule_requires_relation_tail (error case)
  • Updated all existing Statement::Comment destructures in tests/sqlparser_postgres.rs to include the two new fields.

Adds parser + AST coverage for the three remaining COMMENT ON shapes
that pgmold-sqlparser had been silently rejecting:

- `COMMENT ON CONSTRAINT name ON [DOMAIN] target IS '…'`
- `COMMENT ON OPERATOR name (left, right) IS '…'` (each side may be NONE)
- `COMMENT ON RULE name ON target IS '…'`

`Statement::Comment` gains two fields: `operator_args:
Option<CommentOperatorArgs>` (operand types for OPERATOR, modeled as
`Option<DataType>` per side so unary `NONE` is preserved), and
`on_domain: bool` (set when CONSTRAINT uses the `ON DOMAIN <domain>`
form). The existing `arguments` and `table_name` fields keep their
prior semantics for FUNCTION/PROCEDURE/AGGREGATE and TRIGGER/POLICY.

Refactors `parse_drop_operator_signature` to share the new
`parse_operator_arg_type_or_none` helper with `parse_comment`, since
both parse the `{ DataType | NONE }` slot shape.

Bumps fork to 0.63.0 and adds changelog/0.63.0.md.
@fmguerreiro fmguerreiro merged commit a42e727 into main Apr 27, 2026
19 checks passed
@fmguerreiro fmguerreiro deleted the pgmold-297/comment-constraint-operator-rule branch April 27, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant